//
//  LSTabbarViewController.m
//  KuaiYi
//
//  Created by ZengFanSheng on 2016/11/13.
//  Copyright © 2016年 HeiMa. All rights reserved.
//

#import "LSTabbarViewController.h"
#import "LSNavigationViewController.h"
#import "LSCustomButton.h"

@interface LSTabbarViewController ()

@end

@implementation LSTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tabBar.tintColor = [UIColor orangeColor];
    
    NSArray *classNames = @[@"LSHomeViewController", @"LSDiscoverViewController", @"LSHealthViewController"];
    NSArray *titles = @[@"首页", @"发现", @"健康",];
    NSArray *imageNames = @[@"tab_normal_1", @"tab_normal_2", @"tab_normal_3"];
    
    
    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 0; i < classNames.count; i++) {
        UIViewController *vc = [self tabbarItemWithClassName:classNames[i] AndTitle:titles[i] AndIconName:imageNames[i]];
        [arrayM addObject:vc];
    }
    
    self.viewControllers = [arrayM copy];
}


- (UIViewController *)tabbarItemWithClassName:(NSString *)className AndTitle:(NSString *)title AndIconName:(NSString *)iconName
{
    Class class = NSClassFromString(className);
    UIViewController *vc = [[class alloc] init];
    vc.title = title;
    
    NSAssert([vc isKindOfClass:[UIViewController class]], @"class不是UIViewController类型");
    
    NSString *selectedImageName = [iconName stringByAppendingString:@"_selected"];
    
    vc.tabBarItem.image = [UIImage imageNamed:iconName];
    UIImage *selectedImg = [UIImage imageNamed:selectedImageName];
    vc.tabBarItem.selectedImage = [selectedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.view.backgroundColor = [UIColor whiteColor];
//    [vc setHidesBottomBarWhenPushed:YES];

    LSCustomButton *leftItem = [[LSCustomButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
    [leftItem setBackgroundImage:[UIImage imageNamed:@"menusnew"] forState:UIControlStateNormal];
    vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftItem];
    [leftItem addTarget:self action:@selector(leftItemClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    LSNavigationViewController *nav = [[LSNavigationViewController alloc] initWithRootViewController:vc];
    nav.tabBarItem.image = [UIImage imageNamed:iconName];
    
    return nav;
}

#pragma mark - navigationBarItem点击事件
-(void)leftItemClick:(UIButton *)sender
{
    ICSDrawerController *drawer = (ICSDrawerController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    [drawer open];
}

- (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController
{
    self.view.userInteractionEnabled = NO;
}

- (void)drawerControllerDidClose:(ICSDrawerController *)drawerController
{
    self.view.userInteractionEnabled = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
